import pygame
import os

'''配置文件'''

# --- 基础设置 ---
WIDTH = 1200 # Keep the increased width
HEIGHT = 760
SCREENSIZE = (WIDTH, HEIGHT)
GRID_SIZE = 20

assert WIDTH % GRID_SIZE == 0, "Screen width must be a multiple of GRID_SIZE"
assert HEIGHT % GRID_SIZE == 0, "Screen height must be a multiple of GRID_SIZE"
GRID_WIDTH = WIDTH // GRID_SIZE
GRID_HEIGHT = HEIGHT // GRID_SIZE

# --- 颜色定义 ---
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
PURPLE = (255, 0, 255)
CYAN = (0, 255, 255)
GRAY = (128, 128, 128)
DARK_GRAY = (50, 50, 50)
LIGHT_GRAY = (100, 100, 100)
GRID_COLOR = (40, 40, 40)
GOLD = (255, 215, 0)

SNAKE_COLOR_OPTIONS = {
    "绿色": GREEN, "蓝色": BLUE, "黄色": YELLOW, "紫色": PURPLE
}
SNAKE_HEAD_COLOR_DEFAULT = (255, 100, 100) # Example, Snake class calculates brighter color

FOOD_COLOR = RED # Normal food is always Red
POISON_FOOD_COLOR = BLUE # Poison food is Blue (shrinks snake)
TRAP_COLOR = WHITE

# --- 关卡设置 (MODIFIED TARGET SCORES) ---
# Adjusted target scores for better progression
# Each food = 10 points
LEVELS = [
    {"traps": 0, "target_score": 10, "speed": 10, "poison": False}, # Level 1: Requires 2 food items
    {"traps": 3, "target_score": 30, "speed": 12, "poison": False}, # Level 2: Requires 3 food items + traps
    {"traps": 3, "target_score": 60, "speed": 12, "poison": True},  # Level 3: Requires 4 food items + traps + poison
    {"traps": 5, "target_score": 100, "speed": 15, "poison": True},  # Level 4: Requires 5 food items + more traps + poison + faster
    {"traps": 8, "target_score": 150, "speed": 18, "poison": True}   # Level 5: Requires 6 food items + many traps + poison + fastest
]
MAX_LEVEL = len(LEVELS)

# --- 难度设置 ---
DIFFICULTY_SETTINGS = {"简单": 0.5, "普通": 1.0, "困难": 1.3}
DEFAULT_DIFFICULTY = "普通"

# --- 资源路径 ---
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
RESOURCES_DIR = os.path.join(BASE_DIR, 'resources')
FONT_DIR = os.path.join(RESOURCES_DIR, 'font')
AUDIO_DIR = os.path.join(RESOURCES_DIR, 'audio')
USERINFO_DIR = os.path.join(BASE_DIR, 'userinfo')

FONT_PATH_CN = os.path.join(FONT_DIR, 'STXIHEI.TTF') # Main font (Chinese, Letters)
FONT_PATH_NUM = os.path.join(FONT_DIR, 'Gabriola.ttf') # Number font

# --- 字体加载 ---
pygame.font.init()
# Main Font (STXIHEI)
try:
    FONT_MAIN_SMALL = pygame.font.Font(FONT_PATH_CN, 25)
    FONT_MAIN_MEDIUM = pygame.font.Font(FONT_PATH_CN, 30)
    FONT_MAIN_LARGE = pygame.font.Font(FONT_PATH_CN, 50)
    FONT_MAIN_XLARGE = pygame.font.Font(FONT_PATH_CN, 70)
except pygame.error as e:
    print(f"警告: 加载主字体 '{FONT_PATH_CN}' 失败: {e}. 使用系统默认字体。")
    FONT_MAIN_SMALL = pygame.font.SysFont(None, 28)
    FONT_MAIN_MEDIUM = pygame.font.SysFont(None, 35)
    FONT_MAIN_LARGE = pygame.font.SysFont(None, 55)
    FONT_MAIN_XLARGE = pygame.font.SysFont(None, 75)

# Number Font (Gabriola)
try:
    FONT_SCORE = pygame.font.Font(FONT_PATH_NUM, 40)
except pygame.error as e:
    print(f"警告: 加载数字字体 '{FONT_PATH_NUM}' 失败: {e}. 使用系统默认字体。")
    FONT_SCORE = pygame.font.SysFont(None, 40)

# --- 音频加载 ---
# Mixer initialization moved to main.py

# Load SFX path info (actual loading requires initialized mixer)
SFX_EAT = None
SFX_DIE = None
SFX_LEVELUP = None
SOUND_ENABLED = False # Will be set based on successful loading in main
EAT_PATH = os.path.join(AUDIO_DIR, 'eat.wav')
DIE_PATH = os.path.join(AUDIO_DIR, 'die.wav')
LEVELUP_PATH = os.path.join(AUDIO_DIR, 'levelup.wav')

# Load BGM path info
BGM_PATH = os.path.join(AUDIO_DIR, 'bgm.mp3')
BGM_ENABLED = False # Will be set based on file existence check in main
if os.path.exists(BGM_PATH):
    BGM_ENABLED = True
    # print("背景音乐文件找到。") # Print moved to main after mixer init check
else:
    print(f"警告: 背景音乐文件未找到: {BGM_PATH}. 背景音乐将被禁用。")

# --- 成就排行榜路径 ---
ACHIEVEMENTS_FILE = os.path.join(USERINFO_DIR, 'achievements.txt')

# --- 其他常量 ---
INITIAL_SNAKE_LENGTH = 4
INITIAL_SNAKE_GRID_POS = [5, 5] # Starting position grid coordinates
